import { useState } from "react";

// 设置loading
// 尝试自定义设置loading 如果响应时间小于一秒钟 则不会显示loading 然 完成加载去除等待时间
export default function useLoading(boo) {
  const [loading, handlerLoading] = useState(boo);
  let timer = null;
  return [
    loading,
    function (boo) {
      if (boo) {
        timer = setTimeout(handlerLoading.bind(this, boo), 1000);
      } else {
        clearTimeout(timer);
        handlerLoading(boo);
      }
    },
  ];
}
